/**
 * Angular 2 decorators and services
 */
import 'rxjs/add/operator/map';

import {Component, OnInit, ViewEncapsulation} from '@angular/core';
import {environment} from 'environments/environment';
import {Observable} from 'rxjs/Rx';

import {AppState} from '../../app.service';
import {SurveySummary} from '../../models/survey.summary';
import {SurveyService} from '../../services/survey.service';

/**
 * App Component
 * Top Level Component
 */
@Component({
  selector: 'home',
  encapsulation: ViewEncapsulation.None,
  styleUrls: [
    './home.component.css'
  ],
  templateUrl: './home.component.html'
})
export class HomeComponent implements OnInit {
  popularSurveys: Array<SurveySummary>;
  latestSurveys: Array<SurveySummary>;

  public showDevModule: boolean = environment.showDevModule;

  constructor(public appState: AppState, private surveySerivce: SurveyService) {}

  public ngOnInit() {
    this.surveySerivce.getPopularSurveys().subscribe((res) => {
      this.popularSurveys = res.content;
    });
    this.surveySerivce.getLatestSurveys().subscribe((res) => {
      this.latestSurveys = res.content;
    });
    console.log('Initial App State', this.appState.state);
  }
}

/**
 * Please review the https://github.com/AngularClass/angular2-examples/ repo for
 * more angular app examples that you may copy/paste
 * (The examples may not be updated as quickly. Please open an issue on github
 * for us to update it) For help or questions please contact us at @AngularClass
 * on twitter or our chat on Slack at https://AngularClass.com/slack-join
 */
